package com.sdstc.modules.vo;

import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * 机构预设、实际、超编类
 */
@Data
public class OrgTypeVo implements Serializable {
    //编制总数
    private Integer prepareTotal;
    //实际人数
    private Integer actualNum;
    //超编总数
    private Integer overTotal;
    //机构详情
    private List<OrgPeopleVo> typeDetail;

    public void buildTotal(OrgTypeVo orgTypeVo,List<OrgPeopleVo> typeDetail){
        //编制总数
        AtomicReference<Integer> prepareTotal = new AtomicReference<>(0);
        //实际人数
        AtomicReference<Integer> actualNum = new AtomicReference<>(0);
        //超编总数
        AtomicReference<Integer> overTotal = new AtomicReference<>(0);
        typeDetail.forEach(op -> {
            prepareTotal.updateAndGet(v -> v + op.getPrepareTotal());
            actualNum.updateAndGet(v -> v + op.getActualNum());
            overTotal.updateAndGet(v -> v + op.getOverTotal());
        });
        orgTypeVo.setPrepareTotal(prepareTotal.get());
        orgTypeVo.setActualNum(actualNum.get());
        orgTypeVo.setOverTotal(overTotal.get());
    }
}
